package com.py.credit.service.impl;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.py.credit.dao.CardsDao;
import com.py.credit.entity.Cards;
import com.py.credit.entity.Enterprise;
import com.py.credit.service.CardsService;
import com.py.credit.utils.SQLBuilder;
import com.py.credit.utils.UuidUtil;
import com.py.framework.core.common.Page;

@Service
public class CardsServiceImpl implements CardsService {

	@Autowired
	private CardsDao cardsDao;

	@Override
	public void add(Cards card) {
		String cardId = UuidUtil.getUUid();
		card.setId(cardId);
		cardsDao.add(card);
	}

	@Override
	public void edit(Cards card) {
		cardsDao.edit(card);
	}

	@Override
	public List<LinkedHashMap<String, Object>> selectCardsInfoForPage(String zjName, String type, String userId,
			String sign, List<String> showColumns, String[] additionalColumns, String condition, Page page) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		Map<String, String> cardsMap = new HashMap<>();
		cardsMap.put("cardName", zjName);
		cardsMap.put("type", type);
		cardsMap.put("userId", userId);
		cardsMap.put("sign", sign);
		return cardsDao.selectCardsByConditionForPage(cardsMap, showColumns, additionalColumns, conditions, page);
	}

	@Override
	public Cards selectCardsDetail(String id, String sign, String type, String userId, String shzt) {
		Map<String, String> cardsMap = new HashMap<>();
		cardsMap.put("id", id);
		cardsMap.put("sign", sign);
		cardsMap.put("type", type);
		cardsMap.put("userId", userId);
		cardsMap.put("shzt", shzt);
		return cardsDao.selectCardsDetail(cardsMap);
	}

	@Override
	public Long selectCardsSfyzz(String id, String sign, String type, String userId, String shzt) {
		Map<String, String> cardsMap = new HashMap<>();
		cardsMap.put("id", id);
		cardsMap.put("sign", sign);
		cardsMap.put("type", type);
		cardsMap.put("userId", userId);
		cardsMap.put("shzt", shzt);
		return cardsDao.selectCardsSfyzz(cardsMap);
	}

	@Override
	public Long selectCardsZzsfdq(String id, String sign, String type, String userId, String shzt) {
		Map<String, String> cardsMap = new HashMap<>();
		cardsMap.put("id", id);
		cardsMap.put("sign", sign);
		cardsMap.put("type", type);
		cardsMap.put("userId", userId);
		cardsMap.put("shzt", shzt);
		return cardsDao.selectCardsZzsfdq(cardsMap);
	}

	@Override
	public void delete(List<String> cardIds) {
		cardsDao.delete(cardIds);
	}

	@Override
	public Integer selectCount(String cardId) {
		return cardsDao.selectCount(cardId);
	}

	@Override
	public void addReportEnterprise(Enterprise enter) {
		cardsDao.addRelation(enter);

	}

	@Override
	public List<LinkedHashMap<String, Object>> selectEnterpriseForPage(String mainName, String mainType, String zzzt,
			List<String> showColumns, String[] additionalColumns, String condition, Page page) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		Map<String, String> params = new HashMap<>();
		params.put("mainName", mainName);
		params.put("mainType", mainType);
		params.put("zzzt", zzzt);
		return cardsDao.selectEnterpriseByConditionForPage(params, showColumns, additionalColumns, conditions, page);
	}

	@Override
	public void updateCardShzj(String id, String shzt) {
		Map<String, String> params = new HashMap<>();
		params.put("id", id);
		params.put("shzt", shzt);
		cardsDao.updateCardShzj(params);

	}

	@Override
	public void addHistory(String shr, String bz, long id, String shyj, String shjg) {
		Map<String, Object> params = new HashMap<>();
		params.put("shr", shr);
		params.put("bz", bz);
		params.put("ztId", id);
		params.put("shyj", shyj);
		params.put("shjg", shjg);
		cardsDao.addHistory(params);
	}

	@Override
	public List<LinkedHashMap<String, Object>> selectHistory(String id) {

		return cardsDao.selectHistory(id);

	}

	@Override
	public void updateCardStatus(String userId) {
		cardsDao.updateCardStatus(userId);

	}

	@Override
	public List<String> selectCardIdByUserId(String userId, String type) {
		return cardsDao.selectCardIdByUserId(userId, type);
	}

	@Override
	public void updateCardShzjByUserId(String userId, String shzt) {

		Map<String, String> params = new HashMap<>();
		params.put("userId", userId);
		params.put("shzt", shzt);
		cardsDao.updateCardShzjByUserId(params);

	}

	@Override
	public List<LinkedHashMap<String, Object>> selectCardsForPage(String type, String userId, String shzt, Page page) {
		Map<String, String> params = new HashMap<>();
		params.put("type", type);
		params.put("userId", userId);
		params.put("sign", shzt);
		return cardsDao.selectCards(params);
	}

	@Override
	public void updateCardSinStatus(String id) {
		cardsDao.updateCardSinStatus(id);

	}

	@Override
	public Map<String, Object> selectUserinfo(String id) {

		return cardsDao.selectUserinfo(id);
	}

}
